package com.sgj.common.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Calendar;

/**
 * MybatisPlus 自动填充时间
 * @author 沈国纪
 * @date 2021/12/16 21:23
 */
@Component
public class MeatObjectHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		this.setFieldValByName("gmtCreate", Calendar.getInstance().getTime(), metaObject);
		this.setFieldValByName("gmtModified", Calendar.getInstance().getTime(), metaObject);

	}

	@Override
	public void updateFill(MetaObject metaObject) {
		this.setFieldValByName("gmtModified", Calendar.getInstance().getTime(), metaObject);
	}
}